<?php


namespace App\Validator\Rule;


use App\Annotation\Mapping\IsRequired;
use App\Exception\HttpException;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Validator\Contract\RuleInterface;

/**
 * Class IsRequiredRule
 * @Bean(IsRequired::class)
 * @package App\Validator\Rule
 */
class IsRequiredRule implements RuleInterface
{

    public function validate(array $data, string $propertyName, $item, $default = null, $strict = false): array
    {
        if (!trim($data[$propertyName])){
            throw new HttpException($item->getMessage(), 1);
        }
        return $data;
    }
}
